﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Practices.Unity;
using Condimar.Entities;
using Condimar.BussinesLogic;

namespace Condimar.UI
{
    public partial class FrmProveedor : Form
    {
          [Dependency]
        public IProveedorBL proveedorBL { get; set; }
      
        public FrmProveedor()
        {
            InitializeComponent();
            this.BuildUp();
        }

        private void rbRuc_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void rbNombre_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (rbRuc.Checked)
                proveedorBindingSource.DataSource = proveedorBL.GetFromProveedorByRuc(textBox1.Text);

            else
                if (rbNombre.Checked)
                    proveedorBindingSource.DataSource = proveedorBL.GetFromProveedorByRazonSocial(textBox1.Text);     
        }

        private void button2_Click(object sender, EventArgs e)
        {
            FrmMttProveedor frm = new FrmMttProveedor();
            frm.Nuevo();
            frm.ShowDialog();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Proveedor currentProveedor = proveedorBindingSource.Current as Proveedor;
            if (currentProveedor != null)
            {
                FrmMttProveedor frmmttproveedor = new FrmMttProveedor();
                frmmttproveedor.CurrentProveedor = currentProveedor;
                frmmttproveedor.Editar();
                frmmttproveedor.ShowDialog();
            }
            else
            {
                MessageBox.Show("Mensaje", "Seleccione un Item", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            Proveedor currentProveedor = proveedorBindingSource.Current as Proveedor;
            if (currentProveedor != null)
            {
                DialogResult rpta = MessageBox.Show("¿Seguro que desea eliminar el registro?", "Mensaje", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                if (rpta == DialogResult.Yes)
                {
                    proveedorBL.RemoveProveedor(currentProveedor.Id);
                    // MessageBox.Show("Eliminacion Correcta", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    proveedorBindingSource.DataSource = proveedorBL.GetAllFromProveedor();
                }
            }
            else
            {
                MessageBox.Show("Seleccione un Item", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
        }
        }
    }

